package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/validatecode")
public class ValidatecodeConreoller {

    @Autowired
    private OrderService orderService;

    /**
     * 预约发送验证码
     * @param telephone
     */
    @PostMapping("/send4Order")
    public Result send4Order(String telephone){

        try {
            orderService.saveValidateCode(telephone);
            return new Result(true, MessageConstant.SEND_VALIDATECODE_SUCCESS,null);
        } catch (Exception e) {
            return new Result(false, MessageConstant.SEND_VALIDATECODE_FAIL,null);
        }
    }

    /**
     * 登录发送验证码
     * @param telephone
     */
    @GetMapping("/send4Login")
    public Result send4Login(String telephone){
        try {
            orderService.saveValidateCode(telephone);
            return new Result(true, MessageConstant.SEND_VALIDATECODE_SUCCESS,null);
        } catch (Exception e) {
            return new Result(false, MessageConstant.SEND_VALIDATECODE_FAIL,null);
        }
    }
}
